<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

    <?php
    
        session_start();
        
        if(!isset($_SESSION['user'])) {
            header("Location: ../admViews/Login.php");
        } 
        
        require_once '../table_object/User.php';
        $User = new User();
        $ListOfUsers = $User->listAll();
    ?>

    <head>
	<link href="../css/Main.css" rel="stylesheet" type="text/css">
        <title>Web App Dev - Mcgill - <?php echo $_SESSION['user']; ?></title>
    </head>
    
    <body>
        <h3>User Master - List All</h3>
	<form name="form" method="post">
            <table class="tablesorter"> 
                <thead> 
                    <tr>
                        <th title="Id">Id</th>
                        <th title="User Name">Name</th>
                        <th title="User login">User</th>
                        <th title="Update record">Update</th>
                        <th title="Delete record">Delete</th>
                    </tr>
                </thead> 
                <tbody>
                    <?php for($i = 0; $i < count($ListOfUsers); ++$i) { ?>
                        <tr class="<?php if($i % 2 === 0) { echo "even"; } else { echo "odd"; } ?>">
                            <td>
                                <?php echo $ListOfUsers[$i]->get_id(); ?>
                            </td>
                            <td>
                                <img src="../icons/Profile.png"/> 
                                <?php echo $ListOfUsers[$i]->get_name(); ?>
                            </td>
                            <td>
                                <?php echo $ListOfUsers[$i]->get_user(); ?>
                            </td>
                            <td align="center">
                                <a href="./UserUpdate.php?id=<?php echo $ListOfUsers[$i]->get_id(); ?>&action=prepareUpdate">
                                    <img src="../icons/Load.png"/>
                                </a> 
                            </td>
                            <td align="center">
                                <a href="./UserDelete.php?id=<?php echo $ListOfUsers[$i]->get_id(); ?>&action=delete">
                                    <img src="../icons/delete.png"/> 
                                </a>
                            </td>
                        </tr>
                    <?php } ?>
                </tbody>    
            </table>
        </form>
        <form action="./UserCreate.php" method="post">
            <table>
                <tr>
                    <td>
                        <input type="submit" value="Create">
                    </td>
                </tr>
            </table>
        </form>
   </body>
</html>









